{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a94bbb67",
   "metadata": {},
   "source": [
    "## jupyter notebook 扩展介绍\n",
    "1. 使用目录，让工作更加便捷\n",
    "2. jupyter 的快捷使用"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7dce12ef",
   "metadata": {},
   "source": [
    "- 进入命令模式之后（此时你没有活跃单元），你可以尝试以下快捷键：\n",
    "\n",
    "1. A 会在活跃单元之上插入一个新的单元，B 会在活跃单元之下插入一个新单元。\n",
    "2. 连续按两次 D，可以删除一个单元。\n",
    "3. 撤销被删除的单元，按 Z。\n",
    "4. Y 会将当前活跃的单元变成一个代码单元。\n",
    "5. 按住 Shift +上或下箭头可选择多个单元。在多选模式时，按住 Shift + M 可合并你的选择。\n",
    "6. 按 F 会弹出「查找和替换」菜单。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6a2c8dc",
   "metadata": {},
   "source": [
    "- 处于编辑模式时（在命令模式时按 Enter 会进入编辑模式），你会发现下列快捷键很有用：\n",
    "\n",
    "1. Ctrl + Home 到达单元起始位置。\n",
    "2. Ctrl + S 保存进度。\n",
    "3. 如之前提到的，Ctrl + Enter 会运行你的整个单元块。\n",
    "4. Alt + Enter 不止会运行你的单元块，还会在下面添加一个新单元。\n",
    "5. Ctrl + Shift + F 打开命令面板。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ec50e191",
   "metadata": {},
   "source": [
    "## 常用模块"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b7320cc9",
   "metadata": {},
   "source": [
    "- 常用模块\n",
    "- for 循环\n",
    "- for 循环 配合内置函数 range（）的使用"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3a036bc1",
   "metadata": {},
   "source": [
    "### 常用模块"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "316dcfac",
   "metadata": {},
   "source": [
    "- datetime 模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "14621e84",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 调用模块\n",
    "import datetime\n",
    "# datetime.(按TAp键查询)\n",
    "# help(datetime)\n",
    "\n",
    "# 我们可以使用moudle_name.Tap键来查看该模块的所有方法，但不能查看所有方法的细则及使用场景，help 可以帮助我们来做这件事"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "b17a6100",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.date(2021, 11, 16)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# datetime 里面的 date 方法\n",
    "datetime.date.today()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "eba10672",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "16"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# datetime 里面的 date 方法 取出年月日\n",
    "datetime.date.today().day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a2ffeaa4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "11"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.date.today().month"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4bd9790d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2021"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.date.today().year"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "62e47089",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2021-11-16'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# datetime 中 isoformat 格式化年月日\n",
    "datetime.date.isoformat(datetime.date.today())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6931f89a",
   "metadata": {},
   "source": [
    "- time模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "0a86d0b6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "9fdd69ae",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2021, tm_mon=11, tm_mday=16, tm_hour=13, tm_min=23, tm_sec=37, tm_wday=1, tm_yday=320, tm_isdst=0)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 国际标准时间\n",
    "time.gmtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "9c4ce372",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2021, tm_mon=11, tm_mday=16, tm_hour=21, tm_min=23, tm_sec=38, tm_wday=1, tm_yday=320, tm_isdst=0)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 本地时间\n",
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "a5b23e10",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'21:23'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.strftime(\"%H:%M\")\n",
    "## 中间符号可自定义"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "d35fb6c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2021-11-16'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用time 的strftime方法 找到 年月日 然后拼接在一起即可\n",
    "time.strftime(\"%Y-%m-%d\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "c83df4b5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'PM'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.strftime(\"%p\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1e50e044",
   "metadata": {},
   "source": [
    "- random模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "76527be5",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "cb71a59d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.41074651301114173"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# (0,1)的随机数\n",
    "random.random()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "f33c3d4c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1—26的随机数\n",
    "random.randint(1,26)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "83892d85",
   "metadata": {},
   "source": [
    "- for循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "60cf9753",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Not an odd minute.\n"
     ]
    }
   ],
   "source": [
    "# 课本例题\n",
    "from datetime import datetime\n",
    "\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "right_this_minute = datetime.today().minute # datetime.today().minute 当前的时间的分钟\n",
    "\n",
    "if right_this_minute in odds:\n",
    "    print(\"This minute seems a little odd.\")\n",
    "else:\n",
    "    print(\"Not an odd minute.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "5a031c3c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A---101\n",
      "B---102\n",
      "C---103\n"
     ]
    }
   ],
   "source": [
    "names = ['A','B','C']\n",
    "# enumerate 枚举 产生steps的位置索引值（index）\n",
    "# for i in names : 取到了names中的值（values）\n",
    "# for 遍历数据的重要操作\n",
    "for k,i in enumerate(names):\n",
    "    print(i+\"---\"+str(100+k+1))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "400d00d0",
   "metadata": {},
   "source": [
    "- 练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "caa192d0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "grade:2\n"
     ]
    }
   ],
   "source": [
    "a = input(\"grade:\") #input是一个输入栏，输入下面其中代码就有相应的结果。\n",
    "if a == \"1\":\n",
    "    print(\"freshman!come on!\")\n",
    "elif a == \"2\":\n",
    "    condition = input(\"sophomore!keep it on!\")\n",
    "    if condition == \"3\":\n",
    "        print(\"junior!you look like tired~\")\n",
    "    else:\n",
    "        print(\"ok!I know what your mean\")\n",
    "else:\n",
    "    print(\"Work, work, work.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c25af0fc",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
